var Bind = require('./Bind');
var RUNTIME_NAMES = require('./StringEscape').RUNTIME_NAMES;
var expParser = require('./expParser');
var o = RUNTIME_NAMES.TOP_SCOPE + ',' + RUNTIME_NAMES.SUB_SCOPE + ',' + RUNTIME_NAMES.CALLER;
module.exports = {
    requireBlock: true,
    precompile: function (e, t, i) {
        var n = t.match(/^\{\{\s*([$_a-zA-Z][$_a-zA-Z0-9]*)\s*=(.+)\}\}$/);
        if (!n)
            throw new Error('Illegal expression is found in wx:alias.');
        var a = n[1];
        var s = expParser.parse(n[2]);
        var l = expParser.lvalueStringify(s, i);
        var d = expParser.searchBindingPaths([s], i);
        return {
            s: [a],
            d: 'function(' + o + '){return ' + expParser.stringify(s, i) + '}',
            l: l,
            b: d
        };
    },
    register: function (e, t, i) {
    },
    create: function (e, t, i, a, r, o, s, l, d, A) {
        var c = t.s[0];
        var h = Bind.create(c, o, s, t.d, t.l, t.b);
        var u = {};
        var p = '';
        for (p in s)
            u[p] = s[p];
        u[c] = h;
        var g = {};
        for (p in r)
            g[p] = r[p];
        g[c] = t.d(a, r, null);
        var _ = d.createVirtualNode('wx:alias');
        i.id && (_.id = i.id);
        A(i.c, d, _, a, g, o, u, l);
        return _;
    }
};
